/*
 * @Author: shiyue 2647472992@qq.com
 * @Date: 2024-08-25 21:11:11
 * @LastEditors: shiyue 2647472992@qq.com
 * @LastEditTime: 2024-08-26 08:42:47
 * @FilePath: \ShellSort\shellsort.cpp
 * @Description: 这是默认设置,请设置`customMade`, 打开koroFileHeader查看配置 进行设置: https://github.com/OBKoro1/koro1FileHeader/wiki/%E9%85%8D%E7%BD%AE
 */
#include <iostream>
#include <vector>
#include <ctime>

using namespace std;

class ShellSort{
public:
    ShellSort(vector<int>& array)
    :_array(array)
    ,_size(array.size())
    ,_capacity(array.size())
    {}

    ~ShellSort()
    {}
    void printarray()
    {
        int n = _size;
        for (int i = 0; i < n; ++i)
        {
            cout << _arry[i] << " ";
        }
        cout << endl;
    }
    void Shellinsert(int gap)
    {
        int n = _size - 1;
        while (gap > 1)
        {
            gap /= 2;
            for (int i = 0; i < n - gap; ++i)
            {
                int end = i;
                int tempt = i + gap;
                while (end >= 0 )
                {
                    if (_array[tempt]  < _array[end])
                    {
                        _array[end + gap] = _array[end];
                        end -= gap;
                    }
                    else
                    {
                        break;
                    }
                }
                _array[end + gap] = _array[tempt];
            }
        }
    }

private:
    vector<int> _array;
    int _size;
    int _capacity;

};

int main()
{
    vector<int> array(10,8);
    srand(time(nullptr));

    for (auto &e :array)
    {
        e = rand();
    }
    ShellSort test(array);
    test.printarray();
    test.Shellinsert(10);
    test.printarray();
    return 0;
}